#!/bin/zsh

PID=`ps aux | grep /usr/sbin/sshd | sed '/grep/d' | awk '{ print $1; }' `
LOG_FILE=/var/log/sshd/nohup.log

mkdir -p /var/log/sshd

ok () {
	echo "[ "${GREEN_START}"OK"${GREEN_STOP}" ]"
}

failed () {
	echo "[ "${RED_START}"FAILED"${RED_STOP}" ]"
}

main () {
	if [ $# -gt 0 ]; then
		action=$1
	else
		action=status
	fi
	# echo "action = ${action}"
	case $action in 
		status)
			echo -n "status of service sshd: "
			[ -z ${PID} ] && failed || ok
			;;
		start)
			echo -n "starting sshd: "
			if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
				ssh-keygen -A >> ${LOG_FILE} || failed
			fi
			if [ -z ${PID} ]; then
				/usr/bin/nohup /usr/sbin/sshd >> ${LOG_FILE} &
			fi
			ok
			;;
		*)
			;;
	esac 
}

main $@

# vim: ts=4 sw=4
